home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: giuliano@ix.netcom.com(Giuliano Carlini)
- Newsgroups: comp.lang.c++
- Subject: Re: Why don't you use garbage collection
- Date: 12 Apr 1996 18:11:03 GMT
- Organization: Netcom
- Message-ID: <4km6bn$mpe@dfw-ixnews3.ix.netcom.com>
- References: <4kiai0$mjd@dfw-ixnews8.ix.netcom.com> <316D291F.465D@sto.fdata.se>
- NNTP-Posting-Host: lbx-ca5-03.ix.netcom.com
- X-NETCOM-Date: Fri Apr 12 1:11:03 PM CDT 1996
-
- In <316D291F.465D@sto.fdata.se> Niklas Mellin
- <niklas.mellin@sto.fdata.se> writes:
- >Giuliano Carlini wrote:
- >> - Why don't most C/C++ programmers use it?
- >I don't use it mostly because I tend to put almost every object I use
- >on the stack and not on the heap. The heap usage I hide in low level
- >classes, that typically have some kind of reference counter, and takes
- >care of the deletions.
- But reference counting doesn't collect cycles, is very inefficient, and
- imposes constraints which can't always be met; for example, deriving
- form a particular base class and always using a smart pointers.
-
- >Sometimes it is necessary to put a high level object on the heap, but
- >those cases are so rare that it is not worth the trouble implementing
- >a garbage collector.
- I would think most large C++ programs use the heap a ton. Perhaps I'm
- wrong. Implementing a GC yourself would be impracticle for many, but
- there are at least two general purpose GC libraries. The first is
- freeware available at ftp://parcftp.xerox.com/pub/gc. The second is a
- commercial product from geodesic systems, www.geodesic.com. Both are
- excellent. Disclosure: I'm associated with geodesic, and hope to profit
- from my relationship through licensing fees/royalties.
-
- >And personally I usually don't have any problem
- >remembering the delete or delete[] in those cases.
- It seems to be a common problem among the programmers I meet.
-
- >I am not against it, it is just that I think the stack suits my needs
- >better.
- The stack and static globals are certainly my first choice.
-
- >I agree though that there have been cases I have wished I had
- >a garbage collector. But I don't think a garbage collector fits into
- >the language as well as in Smalltalk or Lisp.
- GC does not require any changes to the language. While it doesn't seem
- to fiFrom: giuliano@ix.netcom.com(Giuliano Carlini)
- Newsgroups: comp.lang.c++
- Subject: Re: Why don't you use garbage collection
- References: <4kiai0$mjd@dfw-ixnews8.ix.netcom.com> <316D291F.465D@sto.fdata.se>
-
- In <316D291F.465D@sto.fdata.se> Niklas Mellin
- <niklas.mellin@sto.fdata.se> writes:
- >Giuliano Carlini wrote:
- >> - Why don't most C/C++ programmers use it?
- >I don't use it mostly because I tend to put almost every object I use
- >on the stack and not on the heap. The heap usage I hide in low level
- >classes, that typically have some kind of reference counter, and takes
- >care of the deletions.
- But reference counting doesn't collect cycles, is very inefficient, and
- imposes constraints which can't always be met; for example, deriving
- form a particular base class and always using a smart pointers.
-
- >Sometimes it is necessary to put a high level object on the heap, but
- >those cases are so rare that it is not worth the trouble implementing
- >a garbage collector.
- I would think most large C++ programs use the heap a ton. Perhaps I'm
- wrong. Implementing a GC yourself would be impracticle for many, but
- there are at least two general purpose GC libraries. The first is
- freeware available at ftp://parcftp.xerox.com/pub/gc. The second is a
- commercial product from geodesic systems, www.geodesic.com. Both are
- excellent. Disclosure: I'm associated with geodesic, and hope to profit
- from my relationship through licensing fees/royalties.
-
- >And personally I usually don't have any problem
- >remembering the delete or delete[] in those cases.
- It seems to be a common problem among the programmers I meet.
-
- >I am not against it, it is just that I think the stack suits my needs
- >better.
- The stack and static globals are certainly my first choice.
-
- >I agree though that there have been cases I have wished I had
- >a garbage collector. But I don't think a garbage collector fits into
- >the language as well as in Smalltalk or Lisp.
- GC does not require any changes to the language. While it doesn't seem
- to fimake it a bit easier to do
- so.
-
- >So why not do as I do? Write low level template classes that takes
- care
- >of the book keeping, and reuse them,
- Because this is buggier than using a GC.
-
- >and don't use the heap more than necessary,
- 100% agreement.
-
- > usually it is easier and more efficient to use the stack.
- Hmmm, I guess we work with diffent types of programs. While it is
- definitly more efficient to use the stack, most large programs that I
- deal with must use the heap.
-
- >
- >> For anyone who may be wondering, I believe that we should use
- garbage
- >> collection because:
- >> - It vastly decreases the number of bugs in programs which
- use
- >> it.
- >
- >It is easier to debug a reference counting class than to debug a
- garbage
- >collector.
- But once the GC is debugged, your done. Reference counting classes will
- require that you meet their constraints. When you don't boom. Which
- means that each time you write new code, you will probably spend time
- debugging where you violated the constraints.
-
- Thanks Niklas for your response. It reinforces my suspicion that most
- people don't even know that GC for C++ is available.
-
- g
-